package com.zhu.config;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    @JsonSerialize(include= JsonSerialize.Inclusion.NON_EMPTY)
    private String code;
    @JsonSerialize(include= JsonSerialize.Inclusion.NON_EMPTY)
    private String message;
    @JsonSerialize(include= JsonSerialize.Inclusion.NON_EMPTY)
    private String time;

    private T result;

    public Result() {
        this.code="200";
        this.message = "成功";
    }
    public Result<T> success(){
        this.code="200";
        this.message="请求成功";
        return this;
    }
    public Result<T> fail(){
        this.code="500";
        this.message="请求失败";
        return this;
    }
    public Result<T> success(T data){
        this.code="200";
        this.message="请求成功";
        this.result = data;
        return this;
    }
    public Result<T> fail(T data){
        this.code="200";
        this.message="请求成功";
        this.result = data;
        return this;
    }

    public Result<T> success(String code, String message){
        this.code=code;
        this.message=message;
        return this;
    }
    public Result<T> fail(String code, String message){
        this.code=code;
        this.message=message;
        return this;
    }
    public Result<T> fail(String code, String message, T data){
        this.code=code;
        this.message=message;
        this.result = data;
        return this;
    }

    public Result<T> success(String code, String message, T data){
        this.code=code;
        this.message=message;
        this.result = data;
        return this;
    }

}
